const app = getApp()
const WXAPI = require("../../../../api/newApi")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[
      {},{},{}
    ],
    isShow: false,
    changeIshow: false,
    lablsit:[
      {id:0 ,name:'我的券'},{id:1 ,name:'我的积分'},
    ],
    pageSize: 30,
    pageNum: 1,
    total: 0,
    lodingtype: 1,//加载状态（0：加载中  1：加载完成没有更多）
    imgHttp: app.globalData.imgHttp, //图片前缀
    checkcouponsLs:[],//选中的券列表
    couponsLs:[], //券列表
    checkintegralLs:[],//选中的积分列表
    integralLs:[], //积分列表
    listIndex:[], //确认页面明细数组
    indexIshow: false,
    fromLs:[], //提交给后端的表单
    changeindex: 0,
    items: [
      {value: 'USA', name: '美国'},
      {value: 'CHN', name: '中国'},
      {value: 'BRA', name: '巴西'},
      {value: 'JPN', name: '日本'},
      {value: 'ENG', name: '英国'},
      {value: 'FRA', name: '法国'}
    ],
    bls:[], //明细列表
    restop: 0,
    blsIshow: false,
    selectAllStatus:false,    // 全选状态(券)
    selectAllStatus_tow: false,  // 全选状态(积分)
    information:{},
    integralWorth: 0,//积分价值合计
    couponsWorth: 0,//券价值合计
    worthTotla: 0, //价值合计数量
    getTotalnum: 0,//获得合计数量
    remark: '', //备注信息
    toCustomerAccount: '',//接收用户账号
    isPassshow: false, //密码弹窗
    isFocus: true, //是否自动聚焦
    Length: 6, //密码长度
    entryList: "",
    active: 0,
    orderId: '', //订单id
    isResult: false, //是否设置密码
    param: '',//扫码参数
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      statusHeight: app.gettop.height,
      status: app.gettop.status,
      navHeight:app.gettop.navHeight,
      mobbleBottom: app.mobile.mobbleBottom
    })
    this.getCouponsList()
    this.getintegralList()
    console.log(options)
    if(options.info==undefined){
      console.log('扫码进入')
      this.data.param = options.param
      this.getInfo()
    }else{
      console.log('其他')
      this.data.information =  JSON.parse(options.info)
      console.log(this.data.information)
      this.setData({
       information: this.data.information
      })
    }
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },
  getheight(){ //获取高度
    var windowHeight = wx.getSystemInfoSync().windowHeight
    console.log(windowHeight)
    var query = wx.createSelectorQuery()
      query.select('.assets_detail').boundingClientRect( (res)=> {
        console.log(res.top);
        this.setData({
          windowHeight: windowHeight - res.top
        })
    }).exec();
  },
  back(){
    wx.reLaunch({
      // url: '/pages/assets/assets',
      url:'/pages/userMarket/userMarket'
    })
  },
  open(){
    this.setData({
      isShow: true
    })
  },
  getInfo(){ //扫二维码后进入获取个人信息 param
    var data = {
      qrCodeUrl: this.data.param
    }
    WXAPI.parGiveQrCodeUrl(data, (res) => {
      const data = res.result
      if (res.code == 200) {
        this.setData({
          information: res.result
         })
      }
    })
  },
  bindscrolltolower(){ //上拉刷新
    console.log("触底了",this.data.pageNum,Math.ceil(this.data.total / this.data.pageSize),this.data.total)
    if (this.data.pageNum >= Math.ceil(this.data.total / this.data.pageSize)) {
      console.log('没有分页')
      this.setData({
        lodingtype: 1
      })
    } else {
      this.setData({
        lodingtype: 0
      })
      this.data.pageNum++; //每触底一次 page + 1;
      if(this.data.changeindex==0){
        this.getCouponsList()
      }else{
        this.getintegralList();
      }
    }
  },
  getCouponsList(){ //获取券列表
    // let couponsLs = this.data.couponsList
    var data = {
      pageNum: this.data.pageNum,
      pageSize: this.data.pageSize,
      assetType: 2,
    }
    WXAPI.zzassetList(data, (res) => {
      const data = res.result
      if (res.code == 200) {
        // if(res.result==''){
        //   this.setData({
        //     ls:'',
        //     // changeindex: 1,
        //     // pageNum: 1
        //   })
        //   return
        // }
        // this.data.couponsLs = res.result.records.map(item=>{
        //   return {
        //     ...item,
        //     checked: false,
        //     amount: 0, //选择数
        //   }
        // })
        this.data.total = res.result.total
        let list = res.result.records.map((item, index)=>{
          return {
            ...item,
            checked: false,
            amount: 0, //选择数
          }
        })
        this.data.couponsLs = list
        if (this.data.pageNum > 1) {
          this.data.couponsLs = this.data.couponsLs.concat(list); //将数据拼接在一起
          this.setData({
            couponsLs: this.data.couponsLs
          })
        } else {
          this.data.couponsLs = list
          this.setData({
            couponsLs: this.data.couponsLs
          })
        }
        console.log(this.data.couponsLs)
        wx.hideLoading({})
      }
    })
   
  },
  checkClick(e){ //选中(券)
    let idx = e.currentTarget.dataset.index;
    let itemx = e.currentTarget.dataset.item;
    let labelInfoList = this.data.couponsLs;
    console.log(labelInfoList)
    labelInfoList[idx].checked = !labelInfoList[idx].checked
    if(labelInfoList[idx].amount<=0 && labelInfoList[idx].checked==true){
      labelInfoList[idx].amount = 1
    }
    this.data.couponsWorth = this.getTotalPrice(labelInfoList)
    console.log(this.data.couponsWorth)
    this.setData({
      worthTotla: this.data.couponsWorth + this.data.integralWorth
    })
    let checkls = labelInfoList.filter((item, index)=>{
      if(item.checked){
        return {
          ...item,
        }
      }
    })
    this.data.checkcouponsLs = checkls
    if(checkls.length==labelInfoList.length){
      console.log('全选')
      this.setData({
        selectAllStatus: true
      })
    }else{
      this.setData({
        selectAllStatus: false
      })
    }
    // console.log('选中的券列表+++++',this.data.checkcouponsLs)
    // let checkls2 = checkls.map((item, index)=>{
    //   this.data.couponsWorth = this.getTotalPrice(checkls)
    //     return {
    //       // ...item,
    //       assetId: item.id,
    //       giveCound: item.amount
    //     }
    // })
    // console.log(checkls2)
    this.setData({
      couponsLs: labelInfoList,
      // worthTotla: this.data.couponsWorth + this.data.integralWorth
    })
  },
  selectAll(){ //全选(券)
    let selectAllStatus = this.data.selectAllStatus;    // 是否全选状态
    selectAllStatus = !selectAllStatus;
    let carts = this.data.couponsLs;
    
    for (let i = 0; i < carts.length; i++) {
        carts[i].checked = selectAllStatus;
        if(carts[i].amount<=0){
          carts[i].amount = 1
        }
    }
    this.data.couponsWorth = this.getTotalPrice(carts)
    this.data.checkcouponsLs = carts
    if(selectAllStatus==false){
      this.data.couponsWorth = 0
      this.data.checkcouponsLs = []
      this.setData({
        selectAllStatus: selectAllStatus,
        couponsLs: carts,
        // worthTotla: 0,
        // indexIshow: false,
        checkcouponsLs:[],
        worthTotla: this.data.couponsWorth + this.data.integralWorth,
        bls: this.data.checkcouponsLs.concat(this.data.checkintegralLs)
      });
    }else{
      let list = this.data.checkcouponsLs.concat(this.data.checkintegralLs)
      console.log(list)
      this.setData({
        selectAllStatus: selectAllStatus,
        couponsLs: carts,
        worthTotla: this.data.couponsWorth + this.data.integralWorth,
        bls:list
      });
    }
    
    // let checkls = carts.filter((item, index)=>{
    //   if(item.checked){
    //     return {
    //       ...item,
    //     }
        
    //   }
    // })
    // console.log(checkls)
    // this.data.checkcouponsLs = checkls
    // this.data.bls = this.data.checkcouponsLs.concat(this.data.checkintegralLs)
    // this.setData({
    //   bls:this.data.bls,
    // })
  },
  addCount(e){  //增加数量(券)
    const index = e.currentTarget.dataset.index;
    console.log(index)
    let carts = this.data.couponsLs;
    // carts[index].checked = true
    let amount = parseInt(carts[index].amount);
    
    if(amount >= carts[index].usable){
      console.log(88888888)
      return false;
    }
    amount += 1;
    console.log(typeof(amount),amount,carts,this.data.couponsLs)
    carts[index].amount = amount;
    this.data.couponsWorth = this.getTotalPrice(carts)
    // let checkls = carts.filter((item, index)=>{
    //   if(item.checked){
    //     return {
    //       ...item,
    //     }
    //   }
    // })
    // this.data.checkcouponsLs = checkls
    this.setData({
      couponsLs: carts,
      worthTotla: this.data.couponsWorth + this.data.integralWorth
    });
  },
  minusCount(e){ //减少数量(券)
    const index = e.currentTarget.dataset.index;
    let carts = this.data.couponsLs;
    let amount = carts[index].amount;
    if(amount <= 0){
      return false;
    }
    console.log(carts[index].checked)
    // if(carts[index].checked==true){
    //   if(amount <= 1){
    //     return false;
    //   }
    // }
    // carts[index].checked = true
    amount = amount - 1;
    carts[index].amount = amount;
    // if(amount<=0){
    //   carts[index].checked = false
    // }
    this.data.couponsWorth = this.getTotalPrice(carts)
    this.setData({
      couponsLs: carts,
      worthTotla: this.data.couponsWorth + this.data.integralWorth
    });
  },
  bindinputCoupons(e){ //输入(券)
    const index = e.currentTarget.dataset.index;
    let value = 0
    console.log(value)
    if(value==''){
      console.log('value',value)
      value = Number(e.detail.value)
    }else{
      value = parseInt(e.detail.value)
    }
    let cls = this.data.couponsLs;
    
    if(value>cls[index].usable){
      cls[index].amount = cls[index].usable
      wx.showToast({
        title: '超过最大值，已为您重新修正',
        icon: 'none'
      })
    }
    // else if(cls[index].checked==true){
    //   if(value <= 0){
    //     console.log(value)
    //     cls[index].amount = 1
    //   }
    // }
    else{
      console.log(525555)
      cls[index].amount = value
    }
    this.data.couponsWorth = this.getTotalPrice(cls)
    this.setData({
      couponsLs: cls,
      worthTotla: this.data.couponsWorth + this.data.integralWorth
    })
    // let amount = carts[index].amount;
  },
  getintegralList(){ //获取积分列表
    var data = {
      pageNum: this.data.pageNum,
      pageSize: this.data.pageSize,
      assetType: 1,
    }
    WXAPI.zzassetList(data, (res) => {
      const data = res.result
      if (res.code == 200) {
        // if(res.result==''){
        //   this.setData({
        //     ls:''
        //   })
        //   return
        // }
        this.data.total = res.result.total
        let list = res.result.records.map((item, index)=>{
          return {
            ...item,
            checked: false,
            amount: 0, //选择数
          }
        })
        this.data.integralLs = list
        if (this.data.pageNum > 1) {
          this.data.integralLs = this.data.integralLs.concat(list); //将数据拼接在一起
          this.setData({
            integralLs: this.data.integralLs
          })
        } else {
          this.data.integralLs = list
          this.setData({
            integralLs: this.data.integralLs
          })
        }
        console.log(this.data.integralLs)
        wx.hideLoading({})
      }
    })
  },
  checkClick_two(e){ //选中(积分)
    let idx = e.currentTarget.dataset.index;
    let itemx = e.currentTarget.dataset.item;
    let labelInfoList = this.data.integralLs;
    console.log(labelInfoList)
    labelInfoList[idx].checked = !labelInfoList[idx].checked
    if(labelInfoList[idx].amount<=0 && labelInfoList[idx].checked==true){
      labelInfoList[idx].amount = 1
    }
    this.data.integralWorth = this.getTotalPrice(labelInfoList)
    console.log(this.data.integralWorth)
    this.setData({
      worthTotla: this.data.couponsWorth + this.data.integralWorth
    })
    let checkls = labelInfoList.filter((item, index)=>{
      if(item.checked){
        return {
          ...item,
        }
      }
    })
    this.data.checkintegralLs = checkls
    // console.log('选中的积分列表+++++',this.data.checkintegralLs)
    // let checkls2 = checkls.map((item, index)=>{
    //     return {
    //       // ...item,
    //       assetId: item.id,
    //       giveCound: item.amount
    //     }
    // })
    // console.log(checkls2)
    if(checkls.length==labelInfoList.length){
      console.log('全选')
      this.setData({
        selectAllStatus_tow: true
      })
    }else{
      this.setData({
        selectAllStatus_tow: false
      })
    }
    this.setData({
      integralLs: labelInfoList
    })
  },
  selectAll_two(){ //全选(积分)
    let selectAllStatus = this.data.selectAllStatus_tow;    // 是否全选状态
    selectAllStatus = !selectAllStatus;
    let carts = this.data.integralLs;
    for (let i = 0; i < carts.length; i++) {
        carts[i].checked = selectAllStatus;     // 改变所有商品状态
        if(carts[i].amount<=0){
          carts[i].amount = 1
        }
    }
    this.data.integralWorth = this.getTotalPrice(carts)
    this.data.checkintegralLs = carts
    if(selectAllStatus==false){
      this.data.integralWorth = 0
      this.data.checkintegralLs= []
      this.setData({
        selectAllStatus_tow: selectAllStatus,
        integralLs: carts,
        // worthTotla: 0,
        // indexIshow: false,
        checkintegralLs:[],
        worthTotla: this.data.couponsWorth + this.data.integralWorth,
        bls: this.data.checkcouponsLs.concat(this.data.checkintegralLs)
      });
    }else{
      let list = this.data.checkcouponsLs.concat(this.data.checkintegralLs)
      this.setData({
        selectAllStatus_tow: selectAllStatus,
        integralLs: carts,
        worthTotla: this.data.couponsWorth + this.data.integralWorth,
        bls: list
      });
    }
    
    // let checkls = carts.filter((item, index)=>{
    //   if(item.checked){
    //     return {
    //       ...item,
    //     }
    //   }
    // })
    // console.log(checkls)
    // this.data.checkintegralLs = checkls
    // this.data.bls = this.data.checkcouponsLs.concat(this.data.checkintegralLs)
    //   this.setData({
    //     bls:this.data.bls
    //   })
  },
  addCount_two(e){  //增加数量(积分)
    const index = e.currentTarget.dataset.index;
    console.log(index)
    let carts = this.data.integralLs;
    let amount = parseInt(carts[index].amount);
    if(amount >= carts[index].usable){
      return false;
    }
    amount = amount + 1;
    carts[index].amount = amount;
    this.data.integralWorth = this.getTotalPrice(carts)
    // let checkls = carts.filter((item, index)=>{
    //   if(item.checked){
    //     return {
    //       ...item,
    //     }
    //   }
    // })
    // this.data.checkintegralLs = checkls
    this.setData({
      integralLs: carts,
      worthTotla: this.data.couponsWorth + this.data.integralWorth
    });
  },
  minusCount_two(e){ //减少数量(积分)
    const index = e.currentTarget.dataset.index;
    let carts = this.data.integralLs;
    let amount = carts[index].amount;
    if(amount <= 0){
      return false;
    }
    // if(carts[index].checked==true){
    //   if(amount <= 1){
    //     return false;
    //   }
    // }
    amount = amount - 1;
    carts[index].amount = amount;
    this.data.integralWorth = this.getTotalPrice(carts)
    // let checkls = carts.filter((item, index)=>{
    //   if(item.checked){
    //     return {
    //       ...item,
    //     }
    //   }
    // })
    // this.data.checkintegralLs = checkls
    this.setData({
      integralLs: carts,
      worthTotla: this.data.couponsWorth + this.data.integralWorth
    });
  },
  bindinputCoupons_two(e){ //输入(积分)
    const index = e.currentTarget.dataset.index;
    let value = 0
    console.log(value)
    if(value==''){
      console.log('value',value)
      console.log(886)
      value = Number(e.detail.value)
    }else{
      console.log(88)
      value = parseInt(e.detail.value)
    }
    let cls = this.data.integralLs;
    if(value>cls[index].usable){
      cls[index].amount = cls[index].usable
      wx.showToast({
        title: '超过最大值，已为您重新修正',
        icon: 'none'
      })
    }
    // else if(cls[index].checked==true){
    //   if(value <= 0){
    //     console.log(value)
    //     cls[index].amount = 1
    //   }
    // }
    else{
      cls[index].amount = value
    }
    this.data.integralWorth = this.getTotalPrice(cls)
    this.setData({
      integralLs: cls,
      worthTotla: this.data.couponsWorth + this.data.integralWorth
    })
    // let amount = carts[index].amount;
  },
  putAway(){
    this.setData({
      isShow: false
    })
  },
  change(){
    this.setData({
      changeIshow: true
    })
    this.getheight()
  },
  close(){
    this.setData({
      changeIshow: false
    })
  },
  clickSumit(){ //确认
    let list = this.data.checkcouponsLs.concat(this.data.checkintegralLs)
    console.log(list)
    if(list.length==0){
      wx.showToast({
        title: '请选择转赠的资产',
        icon:'none',
      })
      this.setData({
        totalindex: 0,
        listIndex: [],
        indexIshow: false
      })
      return
    }
    console.log(list)
    let cclist = list.filter((item)=>{
      if(item.amount==''||item.amount<=0){
          return{
            ...item
          }
      }
    })
    console.log(cclist)
    if(cclist.length!=0){
      wx.showToast({
        title: '所选转赠资产数量不能为0',
        icon:'none'
      })
      return
    }
    let total = this.countTotal(list)
    // if(total==0){
    //   wx.showToast({
    //     title: '转赠资产数量不能为0',
    //     icon:'none'
    //   })
    //   return
    // }
    this.setData({
      listIndex: list,
      indexIshow: true,
      changeIshow: false,
      totalindex: total
    })
    this.data.fromLs = list.map((item,index)=>{
      return {
        assetId: item.assetId,
        giveCount: item.amount, //选择数
      }
    })
    console.log(this.data.fromLs)
  },
  textareaInput(e){ //备注信息
    let value = e.detail.value
    this.data.remark = value
  },
  sumitTo(){ //确认兑换
    wx.showLoading({
      title: '加载中',
    })
     var data = {
      remark: this.data.remark, //备注信息
      // toCustomerAccount: this.data.information.customerAccount, //接收用户账号
      details:this.data.fromLs,
      toCustomerId: this.data.information.customerId
    }
    WXAPI.addGive(data, (res) => {
      const data = res.result
      if (res.code == 200) {
        this.data.orderId = res.result
        this.setData({
          isPassshow: true,
          entryList: ''
        })
        wx.hideLoading({})
      }else{
        this.setData({
          isPassshow: false,
          entryList: ''
        })
      }
    })
  },
  getcheckPayPsw(){ //判断是否设置支付密码
    let result = false
    var data = {
      
    }
    WXAPI.checkPayPsw(data, (res) => {
      if (res.code == 200) {
        this.sumitTo()
      }else{
        wx.showModal({
          title: '',
          content: '未设置支付密码，不可支付',
          cancelText: '放弃',
          cancelColor:'#B1B1B1',
          confirmText:'去设置',
          confirmColor:'#FF5800',
          success (res) {
            if (res.confirm) {
              console.log('用户点击确定')
              wx.navigateTo({
                url: '/userPageC/pages/userPersonal/changePayPass/changePayPass',
              })
            } else if (res.cancel) {
              console.log('用户点击取消')
              // _this.setData({
              //   isPassshow: false
              // })
            }
          }
        })
      }
    })
  },
  forget(){ //忘记密码
    wx.navigateTo({
      url: '/userPageC/pages/userPersonal/changePayPass/changePayPass',
    })
  },
  inputFocus() { //点击聚焦
    this.setData({
        isFocus: true
    })
  },
  inputValue(e) { //监听密码输入
    var value = e.detail.value;
    var list= e.detail.value.split('')
    this.setData({
        entryList: value,
        active: list.length
    })
    console.log(list.length)
    console.log(value)
    console.log(this.data.entryList)
    if(list.length>=6){
      wx.showLoading({
        title: '支付中',
      })
       var data = {
        orderId: this.data.orderId, //订单id
        payPwd: value, //支付密码
      }
      WXAPI.pay(data, (res) => {
        if (res.code == 200) {
          wx.hideLoading({})
          let info = JSON.stringify(res.result)
          wx.showToast({
            title: '支付成功',
          })
          setTimeout(()=>{
            this.setData({
              isPassshow: false
            })
            wx.navigateTo({
              url: '/userPageA/pages/transfer/transfer_success/transfer_success?info=' + info,
            })
          },1000)
         
        }
        // else if(res.code == -9999){
        //   console.log('密码错误')
        //   this.setData({
        //     entryList: ''
        //   })
        // }
      })
      
    }
  },
  closePay(){ //关闭密码弹窗
    let _this = this
    wx.showModal({
      title: '',
      content: '是否放弃本次付款',
      cancelText: '放弃',
      cancelColor:'#B1B1B1',
      confirmText:'继续付款',
      confirmColor:'#FF5800',
      success (res) {
        if (res.confirm) {
          console.log('用户点击确定')
        } else if (res.cancel) {
          console.log('用户点击取消')
          _this.setData({
            isPassshow: false,
          })
          _this.data.bls = []
          _this.setData({
            // worthTotla: 0,
            // indexIshow: false,
            checkintegralLs:[],
            checkcouponsLs:[],
            worthTotla: 0,
            pageNum:1,
            bls: [],
            listIndex:[],
            indexIshow:false,
            selectAllStatus: false,
            selectAllStatus_tow: false,
          });
          _this.data.checkcouponsLs = []
          _this.data.checkintegralLs = []
          _this.getCouponsList()
          _this.getintegralList()
        }
      }
    })
  },
  changeLab(e){ //券、积分切换
    let index = e.currentTarget.dataset.index;
    console.log(index)
    this.setData({
      changeindex:index,
    })
  },
  openDetail(){ //打开明细（券）
    console.log(this.data.couponsLs)
    this.data.checkcouponsLs = this.data.couponsLs.filter((item,index)=>{
      if(item.checked){
        if(item.amount==''){
          item.amount= 0
        }
        return {
          ...item,
          
        }
      }
    })
    this.data.checkintegralLs = this.data.integralLs.filter((item,index)=>{
      if(item.checked){
        if(item.amount==''){
          item.amount= 0
        }
        return {
          ...item,
          
        }
      }
    })
    let list = this.data.checkcouponsLs.concat(this.data.checkintegralLs)
    let total = parseInt(this.countTotal(list))
    console.log(total)
    console.log('打开明细，选中的列表',list)
    this.setData({
      blsIshow: true,
      getTotalnum: total,
      bls: list
    })
    // console.log(this.data.checkintegralLs)
    // this.data.bls = this.data.checkcouponsLs.concat(this.data.checkintegralLs)
    // console.log(this.data.bls)
    // let getTotalnum = this.countTotal(this.data.bls, 'amount')
    // let worthTotla = this.getTotalPrice(this.data.bls)
    // this.setData({
    //   blsIshow: true,
    //   bls:this.data.bls,
    //   getTotalnum,
    //   worthTotla
    // })
  },
  closeDetail(){ //关闭明细（券）
    this.setData({
      blsIshow: false
    })
  },
  openDetail_two(){ //打开明细（积分）
    console.log(this.data.integralLs)
    this.data.checkintegralLs = this.data.integralLs.filter((item,index)=>{
      if(item.checked){
        return {
          ...item,
        }
      }
    })
    let list = this.data.checkintegralLs.concat(this.data.checkcouponsLs)
    let total = this.countTotal(list)
    console.log(total)
    console.log('打开明细，选中的列表',list)
    this.setData({
      blsIshow: true,
      getTotalnum: total,
      bls: list
    })
    // this.data.bls = this.data.checkcouponsLs.concat(this.data.checkintegralLs)
    // console.log(this.data.bls)
    // let getTotalnum = this.countTotal(this.data.bls, 'amount')
    // let worthTotla = this.getTotalPrice(this.data.bls)
    // this.setData({
    //   blsIshow: true,
    //   bls:this.data.bls,
    //   getTotalnum,
    //   worthTotla
    // })
  },
  closeDetail_two(){ //关闭明细（积分）
    this.setData({
      blsIshow: false
    })
  },
  
  // countTotal(arr, keyName){ //计算和
  //   let $total = 0;
	//   $total = arr.reduce(function (total, currentValue, currentIndex, arr){
	//     return currentValue[keyName] ? (total + currentValue[keyName]) : total;
	//   }, 0);
	//   return $total;
  // },
  countTotal(arr) { //计算总数量
    let carts = arr;
    let total = 0;
    for(let i = 0; i<carts.length; i++) {
      if(carts[i].checked) {  // 判断选中才会计算价格
        total += parseInt(carts[i].amount)    // 所有价格加起来
      }
    }
    return Math.floor(total * 100) / 100
  },
  getTotalPrice(arr) { //计算总价值
    let carts = arr;
    let total = 0;
    for(let i = 0; i<carts.length; i++) {
      if(carts[i].checked) {  // 判断选中才会计算价格
        total += carts[i].amount * carts[i].worth;    // 所有价格加起来
      }
    }
    return Math.floor(total * 100) / 100
  },
})